package chapter_4.matrix;

import java.util.Arrays;

/**
 * (SquareMatrixMuilt). 
 *
 * @author 汪文波(Wang Wenbo) wenboit@163.com
 * @notes Create on 2021-12-12 23:13
 */
public class Violent {

    public static void main(String[] args) {
        int A[][] = new int[][]{
                {1, 3, 5, 9},
                {4, 9, 3, 12},
                {9, 78, 12, 32},
                {9, 21, 41, 1}
        };

        int B[][] = new int[][]{
                {4, 9, 10, 8},
                {3, 7, 22, 15},
                {9, 13, 26, 22},
                {13, 28, 33, 19}
        };

        int[][] C = multi(A, B);

        System.out.println(Arrays.deepToString(C));
    }

    public static int[][] multi(int[][] A, int[][] B) {

        int rows = A.length;
        int[][] C = new int[rows][rows];

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < rows; j++) {
                C[i][j] = 0;
                for (int k = 0; k < rows; k++)
                    C[i][j] = C[i][j] + A[i][k] * B[k][j];
            }
        }

        return C;
    }

}
